import { createApp, h } from "vue";
import App from "./App.vue";
// reset style sheet
import "@/styles/reset.scss";
// CSS common style sheet
import "@/styles/common.scss";
// iconfont css
import "@/assets/iconfont/iconfont.scss";
// font css
import "@/assets/fonts/font.scss";
// element css
import "element-plus/dist/index.css";
// element dark css
import "element-plus/theme-chalk/dark/css-vars.css";
// custom element dark css
import "@/styles/element-dark.scss";
// custom element css
import "@/styles/element.scss";
// svg icons
import "virtual:svg-icons-register";
// element plus
import ElementPlus from "element-plus";
// element icons
import * as Icons from "@element-plus/icons-vue";
// custom directives
import directives from "@/directives/index";
// vue Router
import router from "@/routers";
// vue i18n
import I18n from "@/languages/index";
// pinia store
import pinia from "@/stores";
// errorHandler
import errorHandler from "@/utils/errorHandler";
import ids from "virtual:svg-icons-names";
import SvgIcon from "@/components/SvgIcon/index.vue";
// import { registerSW } from "virtual:pwa-register";

// registerSW({ immediate: true });

const app = createApp(App);

app.config.errorHandler = errorHandler;
app.config.globalProperties.$icons = [];
app.config.globalProperties.$dict = window.staticConfig.dictionary;
app.config.globalProperties.$urlResource = window?.staticConfig?.urlResource;
app.provide("urlResource", window?.staticConfig?.urlResource);
// register the element Icons component
app.component("SvgIcon", SvgIcon);

Object.keys(Icons).forEach(key => {
  app.config.globalProperties.$icons.push(key);
  app.component(key, Icons[key as keyof typeof Icons]);
});
ids.forEach(key => {
  key = key.replace("icon-", "");
  app.config.globalProperties.$icons.push(key);
  app.component(key, {
    render() {
      return h(SvgIcon, { name: key });
    }
  });
});
app.config.warnHandler = () => null;
app.use(ElementPlus).use(directives).use(router).use(I18n).use(pinia).mount("#app");
